<?php
class News_Form_NewsAdd extends Promotor_Form_Scaffold {
	public function init() {
		$this->setMethod('post');
		$this->setAttrib('enctype', Zend_Form::ENCTYPE_MULTIPART);

		$this->addPrefixPath('Promotor_Form_Decorator_','Promotor/Form/Decorator', self::DECORATOR);
        
		$subForm = $this->_getContentForm();
        $this->addSubForm($subForm, 'contenttab');
        
        $subForm = $this->_getCategoryForm();
        $this->addSubForm($subForm, 'categorytab');
        
        $subForm = $this->_getCalendarForm();
        $this->addSubForm($subForm, 'calendartab');
        
        $subForm = $this->_getSeoForm();
        $this->addSubForm($subForm, 'seotab');
        
        $subForm = $this->_getExForm();
        $this->addSubForm($subForm, 'exttab');
	}

	/**
     * @return Zend_Dojo_Form_SubForm
     */
    protected function _getContentForm() {
    	$subForm = new Zend_Form_SubForm();
        $subForm->setAttribs(array(
            'name'   => 'contenttab',
            'legend' => 'Treść',
        ));
        $subForm->addElement(
                'text',
                'name',
                array(
                    'label' => 'Nazwa strony',
                    'required'  => true,
                )
            );
		
		$subForm->addElement(
                'text',
                'name',
                array(
                    'label' => 'Nazwa strony',
                    'required'  => true,
                )
            );
        $description = new Zend_Form_Element_Textarea('description', array(
			'label'        => 'Opis strony',
			'inheritWidth' => 'true',
            'required' 	   =>true,
        	'description' => 'Jest to opis główny, wymagany'
		));
		$description->addDecorator(new KontorX_Form_Decorator_TinyMCE());
		$subForm->addElement($description);
            
		$content = new Zend_Form_Element_Textarea('content', array(
			'label'        => 'Treść strony',
			'inheritWidth' => 'true',
            'required' 	   =>false,
			'description' => 'Treść strony zawiera treść, która jest widoczna jako szczegół'
		));
		$content->addDecorator(new KontorX_Form_Decorator_TinyMCE());
		$subForm->addElement($content);
		
        return $subForm;
    }
    
	/**
     * @return Zend_Form_SubForm
     */
    protected function _getCategoryForm() {
    	$subForm = new Zend_Form_SubForm();
        $subForm->setAttribs(array(
            'name'   => 'categorytab',
            'legend' => 'Kategoria',
        ));
        
        $locale = $this->getRequest()->getParam('locale');
        
        $tree = new KontorX_Form_Element_JsTree('tree', array(
			'label'        => 'Kategoria',
            'required' 	   => false,
        	'registerInArrayValidator' => false,

        	'jsOptions' => array(
        		'data' => array(
        			'url' => 'site/site/list/format/jsTree/locale/' .$locale ,
        			'async' => false
        		)
        	)
		));
		$subForm->addElement($tree);
		
        return $subForm;
    }
    
	/**
     * @return Zend_Form_SubForm
     */
    protected function _getCalendarForm() {
    	$subForm = new Zend_Form_SubForm();
    	$subForm->addPrefixPath('KontorX_Form_','KontorX/Form');

        $subForm->setAttribs(array(
            'name'   => 'calendartab',
            'legend' => 'Kalendarz',
        ));
        
        $subForm->addElement(
                'date',
                'time_create',
                array(
                    'label' => 'Data utworzenia',
                	'value'  => date('Y-m-d'),
                    'required'  => false,
                	'description' => 'data w formacie RRRR-MM-DD'
                )
            )
            ->addElement(
                'date',
                'time_start',
                array(
                    'label' => 'Data początku publikacji',
                    'required'  => false,
                	'description' => 'data w formacie RRRR-MM-DD'
                )
            )
            ->addElement(
                'date',
                'time_end',
                array(
                    'label' => 'Data końca publikacji',
                    'required'  => false,
                	'description' => 'data w formacie RRRR-MM-DD'
                )
            );

        return $subForm;
    }
    
    /**
     * @return Zend_Form_SubForm
     */
    protected function _getSeoForm() {
    	$subForm = new Zend_Form_SubForm();
        $subForm->setAttribs(array(
            'name'   => 'metatab',
            'legend' => 'Pozycjonowanie'
        ));
        $subForm
        	->addElement(
                'text',
                'alias',
                array(
                    'label' => 'Alias aktualności',
                    'required'  => false,
                    'regExp' => '[\w\d\-\s]+',
                    'invalidMessage' => 'Tylko tekst bez polskich znaków diakrytycznych!',
                	'filters' => array(
                		'strtolower' => new Zend_Filter_StringToLower(),
                		'rewrite' => new KontorX_Filter_Word_Rewrite()
                	),
                	'validators' => array(
                		'db_no_exsists' => new Zend_Validate_Db_NoRecordExists('site','alias')
                	)
                )
            )
            ->addElement(
                'Textarea',
                'title',
                array(
                    'label'      => 'Tytuł aktualności',
                    'trim'       => true
				)
            )
            ->addElement(
                'Textarea',
                'meta_keywords',
                array(
                    'label'      => 'Słowa kluczowe',
                    'trim'       => true
				)
            )
            ->addElement(
                'Textarea',
                'meta_description',
                array(
                    'label'      => 'Opis strony',
                    'trim'       => true
                )
            );
            
        return $subForm;
    }
    
	/**
     * @return Zend_Form_SubForm
     */
    protected function _getExForm() {
    	$subForm = new Zend_Form_SubForm();
        $subForm->setAttribs(array(
            'name'   => 'exttab',
            'legend' => 'Zaawansowane'
        ));
        $subForm
            ->addElement(
            	'checkbox',
            	'publicated',
            	array(
            		'label' => 'Publikować',
            		'value' => 1,
            		'checked' => true
            	)
            )
            ->addElement(
            	'text',
                'local',
                array(
                    'label' => 'Locale',
                    'required'  => false,
                    'regExp' => '[\w\d\-]{2,4}',
                    'invalidMessage' => 'Tylko tekst bez polskich znaków diakrytycznych!',
                	'filters' => array(
                		'strtolower' => new Zend_Filter_StringToLower(),
                		'rewrite' => new KontorX_Filter_Word_Rewrite()
                	)
                )
            );
            
        return $subForm;
    }
}